import Vue from 'vue'
import Vuex from 'vuex'
import AiChatHistorys from '../api/AiChatHistorys/AiChatHistorys'

// 将这个Vuex全局注入，在外面就可以直接用了
Vue.use(Vuex)


//创建vuex实例
export default new Vuex.Store({
	state: {
		AllAiChatLists: AiChatHistorys.AiChatHistorys ,//所有跟ai的聊天记录
		LatlyList: [], //最近的聊天记录
		ComputerNetworkList: AiChatHistorys.getComputerNetworkList(), //计算机网络大分类的聊天记录
		OperatingSystemList: AiChatHistorys.getOperatingSystemList(), //操作系统大分类的聊天记录
		DataStructureList: AiChatHistorys.getDataStructureList(), //数据结构大分类的聊天记录
		ComputerPrincipleList: AiChatHistorys.getComputerPrincipleList(), //计算机组成原理大分类的聊天记录
	},
	mutations: {
		addToLatlyList(state, chatHistory) {
			state.LatlyList.unshift(chatHistory)
		},
		removeFromLatlyList(state, chatHistory) {
			state.LatlyList = state.LatlyList.filter(item => item.historyId !== chatHistory.historyId)
		},
		
		addToAllAiChatLists(state, chatHistory) {
			state.AllAiChatLists.unshift(chatHistory)
		},
		removeFromAllAiChatLists(state, chatHistory) {
			state.AllAiChatLists = state.AllAiChatLists.filter(item => item.historyId !== chatHistory.historyId)
		},
		
		addToComputerNetworkList(state, chatHistory) {
			state.ComputerNetworkList.unshift(chatHistory)
		},
		removeFromComputerNetworkList(state, chatHistory) {
			state.ComputerNetworkList = state.ComputerNetworkList.filter(item => item.historyId !== chatHistory.historyId)
		},
		
		addToOperatingSystemList(state, chatHistory) {
			state.OperatingSystemList.unshift(chatHistory)
		},
		removeFromOperatingSystemList(state, chatHistory) {
			state.OperatingSystemList = state.OperatingSystemList.filter(item => item.historyId !== chatHistory.historyId)
		},
		
		addToDataStructureList(state, chatHistory) {
			state.DataStructureList.unshift(chatHistory)
		},
		removeFromDataStructureList(state, chatHistory) {
			state.DataStructureList = state.DataStructureList.filter(item => item.historyId !== chatHistory.historyId)
		},
		
		addToComputerPrincipleList(state, chatHistory) {
			state.ComputerPrincipleList.unshift(chatHistory)
		},
		removeFromComputerPrincipleList(state, chatHistory) {
			state.ComputerPrincipleList = state.ComputerPrincipleList.filter(item => item.historyId !== chatHistory.historyId)
		}
	},
	actions: {
		addToAllAiChatLists({ commit }, chatHistory) {
			commit('addToAllAiChatLists', chatHistory)
		},
		removeFromAllAiChatLists({ commit }, chatHistory) {
			commit('removeFromAllAiChatLists', chatHistory)
		},
		addToComputerNetworkList({ commit }, chatHistory) {
			commit('addToComputerNetworkList', chatHistory)
		},
		addToOperatingSystemList({ commit }, chatHistory) {
			commit('addToOperatingSystemList', chatHistory)
		},
		addToDataStructureList({ commit }, chatHistory) {
			commit('addToDataStructureList', chatHistory)
		},
		addToComputerPrincipleList({ commit }, chatHistory) {
			commit('addToComputerPrincipleList', chatHistory)
		},
	},
	getters: {
		getAllAiChatLists(state) {
			return state.AllAiChatLists
		},
		getComputerNetworkList(state) {
			return state.ComputerNetworkList
		},
		getOperatingSystemList(state) {
			return state.OperatingSystemList
		},
		getDataStructureList(state) {
			return state.DataStructureList
		},
		getComputerPrincipleList(state) {
			return state.ComputerPrincipleList
		},
	}
})